package gms.service;

import java.util.List;

import org.springframework.stereotype.Component;

import gms.entities.um.User;

@Component
public class UmUtil {
	
	public static User transUser(User user){
		if(user.getAddress()==null)
			user.setAddress("");
		
		if(user.getEmail()==null)
			user.setEmail("");
		
		if(user.getIdCard()==null)
			user.setIdCard("");
		
		if(user.getPhone()==null)
			user.setPhone("");
		
		if(user.getRealName()==null)
			user.setRealName("");
		
		if(user.getUserName()==null)
			user.setUserName("");
		
		if(user.getUserPassword()==null)
			user.setUserPassword("");
		
		return user;
	}
	
	
	public static String getHtmlStr(List<User> user_list){
		String str = "";
		
//		for(int i = 0; i<user_list.size() ; i++){
//			User tem = user_list.get(i);
//			str+="<tr class='list'><td>"+tem.getUserId()+
//					"</td><td><a data-target='#bootstrap' data-toggle='modal' class='modifiUser' href='"+ i +
//					"'>"+tem.getUserName()+"</a></td>"+
//					"<td>"+tem.getUserPassword()+"</td>"+
//					"<td>"+tem.getPhone()+"</td>"+
//					"<td>"+tem.getEmail()+"</td>"+
//					"<td>"+tem.getRealName()+"</td>"+
//					"<td>"+tem.getIdCard()+"</td>"+
//					"<td>"+tem.getAddress()+"<input type='hidden' value="+tem.getRole().getRoleId()+" />"+"</td>"+
//					"<td><a href='um-userDelete?deleteUserId="+tem.getUserId()+"' "+
//					"onclick='javascript: return confirm('���Ҫɾ����');'>ɾ��</a></td></tr>";
//		}
		for(int i = 0; i<user_list.size() ; i++){
			User tem = user_list.get(i);
			str+="<tr class='list'><td>"+tem.getUserId()+
					"</td><td><a data-target='#bootstrap' data-toggle='modal' class='modifiUser' href='"+ i +
					"'>"+tem.getUserName()+"</a></td>"+
					"<td>"+tem.getUserPassword()+"</td>"+
					"<td>"+tem.getPhone()+"</td>"+
					"<td>"+tem.getEmail()+"</td>"+
					"<td>"+tem.getRealName()+"</td>"+
					"<td>"+tem.getIdCard()+"</td>"+
					"<td>"+tem.getAddress()+"<input type='hidden' value="+tem.getRole().getRoleId()+" />"+"</td>"+
					"<td><a href='um-userDelete?deleteUserId="+tem.getUserId()+"'>删除</a></td></tr>";
		}
		
		return str;
	}
	
}
